package com.wlts.wzy.util.http;

import lombok.SneakyThrows;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class JavaSign {

    public static void main(String []args){
        String secret = "749698a6-fcb3-4358-b241-ec1d93cf9c1f";
        String str = secret+"app_key6844048284663924231"+"methodproduct.list"+
                "param_json{\"page\":\"0\",\"size\":\"20\"}"+"timestamp2020-07-05 22:33:59"+"v2"+secret;
        String res = stringToMD5(str);
        System.out.println(res);
    }


    @SneakyThrows
    public static String stringToMD5(String plainText) {
        byte[] secretBytes = null;
        try {
            secretBytes = MessageDigest.getInstance("md5").digest(
                    plainText.getBytes("UTF-8"));
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("没有这个md5算法！");
        }
        StringBuilder md5code = new StringBuilder(new BigInteger(1, secretBytes).toString(16));
        while (md5code.length() < 32) {
            md5code.insert(0, "0");
        }
        return md5code.toString();
    }

}